package com.yjt.fresh.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.HttpManager;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.listener.HttpOnNextListener;
import com.yjt.fresh.R;
import com.yjt.fresh.adpater.AdpRvAtyHelpCenter;
import com.yjt.fresh.adpater.AdpRvAtyMassage;
import com.yjt.fresh.api.ApiGetHelpCenter;
import com.yjt.fresh.base.BaseSimpleActivity;
import com.yjt.fresh.bean.BeanHelp;
import com.yjt.fresh.constant.MyConstants;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 帮助中心
 * Created by mcc on 2018/7/21.
 */

public class AtyHelpCenter extends BaseSimpleActivity {
    @BindView(R.id.back)
    RelativeLayout mBack;
    @BindView(R.id.rvAppAtyHelpCenter)
    RecyclerView mRv;
    @BindView(R.id.btnAppAtyHelpCenterAdvice)
    Button mBtnAdvice;
    private AdpRvAtyHelpCenter mAdpRvAtyHelpCenter;

    @Override
    protected int getContentView() {
        return R.layout.app_aty_help_center;
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);

    }

    @Override
    protected void initEvent() {
        initRV();
        getData();
        initClick();
    }

    private void initRV() {
        LinearLayoutManager manager = new LinearLayoutManager(mContext);
        mRv.setLayoutManager(manager);
        List<BeanHelp> beanHelps= new ArrayList<>();
        mAdpRvAtyHelpCenter = new AdpRvAtyHelpCenter(R.layout.app_recycle_item_help_center, beanHelps);
        mRv.setAdapter(mAdpRvAtyHelpCenter);
    }

    HttpOnNextListener<List<BeanHelp>> mHelpQuestionListener = new HttpOnNextListener<List<BeanHelp>>() {
        @Override
        public void onNext(List<BeanHelp> beanHelps) {
            mAdpRvAtyHelpCenter.setNewData(beanHelps);
        }

        @Override
        public void onReLogin() {
            toLogin();
        }
    };
    private void getData(){
        ApiGetHelpCenter apiGetHelpCenter = new ApiGetHelpCenter(mHelpQuestionListener,mContext,true,false,true);
        HttpManager.getInstance().doHttpDeal(apiGetHelpCenter);
    }

    private void initClick(){
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        mAdpRvAtyHelpCenter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Intent intent = new Intent(mContext,AtyHelpQuestionDetail.class);
                intent.putExtra(MyConstants.HELP_CENTER_TITLE,mAdpRvAtyHelpCenter.getItem(position).getTITLE());
                intent.putExtra(MyConstants.HELP_CENTER_CONTENT,mAdpRvAtyHelpCenter.getItem(position).getCONTENT());
                startActivity(intent);
            }
        });

        mBtnAdvice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,AtyAdvice.class);
                startActivity(intent);
            }
        });
    }
}
